

class Solution {

    public boolean isHappy(int n) {
        int fast=n;
        int slow=n;

        do{
            fast=func(func(fast));
            slow=func(slow);

            if(fast==1||slow==1){
                return true;
            }


        }while(fast!=slow);

        if(fast!=1){

            return false;
        }else{
            return true;
        }




    }





    private int func(int cur){
        int sum=0;
        int n;
        while(cur!=0){
            n=cur%10;
            cur/=10;
            sum+=n*n;
        }

        return sum;

    }

}